package Q2;

public class Solution {
    public static ListNode addInList (ListNode head1, ListNode head2) {
        // write code here
        ListNode curNode = head1;
        int num1 = 0;
        while (curNode != null) {
            num1 = num1 * 10 + curNode.val;
            curNode = curNode.next;
        }

        curNode = head2;
        int num2 = 0;
        while (curNode != null) {
            num2 = num2 * 10 + curNode.val;
            curNode = curNode.next;
        }

        int ret = num1 + num2;
        String str = ret + "";
        char[] ch = str.toCharArray();
        ListNode head = new ListNode(0);
        curNode = head;
        int len = ch.length;
        for (int i = 0; i < len; i++) {
            int num = ch[i] - 49;
            ListNode listNode = new ListNode(num);
            curNode.next = listNode;
            curNode = listNode;
        }

        return head.next;
    }

    public static void main(String[] args) {

        String str = 21345 + "";
        char[] ch = str.toCharArray();
        System.out.println(Integer.valueOf('0').intValue());

    }
}


class ListNode {
    int val;
    ListNode next = null;
    public ListNode(int val) {
        this.val = val;
    }
}

